import {GET,POST} from '@/utils/request.js';

//openid获取
const openid = () => {
	return new Promise((resolve, reject) => {
		let openid = uni.getStorageSync("openid");
		if(openid){
			resolve(openid)
		}else{
			uni.login({
				success(res) {
					if (res.code) {
						POST('/users/getWxOpenid.htm',{code:res.code},true).then(res=>{
								let openid = res.data.data;
								uni.setStorageSync("openid",openid)
								resolve(openid)
						}).catch(err=>{
							reject(err);
						})
					} else {
						reject(res.errMsg);
					}
				}
			
			})
		}

	})
}

//获取appid
const getAppid = () => {
	var accountInfo = wx.getAccountInfoSync();//accountInfo对象中三个参数appid,envVersion和version
	var appid = accountInfo.miniProgram.appId;
	return appid
}


const userLogon = (data = {}) => {
	return POST('/users/userLogon.htm',data,true)
}

export default {
	openid,
	userLogon,
	getAppid,
}
